const vscode = require('vscode');

function pushTextInsertCommand(context, commond, text) {
    context.subscriptions.push(vscode.commands.registerCommand(commond, function () {
        let insertPosition = new vscode.Position(vscode.window.activeTextEditor.selection.active.line, 0);
        vscode.window.activeTextEditor.insertSnippet(new vscode.SnippetString(text), insertPosition);
    }));
}

exports.activate = function (context) {
    //vscode.window.showInformationMessage('extension-markdown-command-assist has activated.');

    context.subscriptions.push(vscode.commands.registerCommand("markdown-command-assist", function () {
        vscode.window.showInformationMessage('Recommend use with extension Markdown Preview Enhanced.');
        vscode.window.showInformationMessage('推荐与插件Markdown Preview Enhanced一起使用。');
    }));

    pushTextInsertCommand(context, "markdown-font-blod", "**_font_blod**");
    pushTextInsertCommand(context, "markdown-font-italic", "*_font_italic*");
    pushTextInsertCommand(context, "markdown-font-italic-blod", "***_font_italic_blod***");
    pushTextInsertCommand(context, "markdown-font-delete", "~~_font_delete~~");
    pushTextInsertCommand(context, "markdown-wrap", "  \r\n");

    pushTextInsertCommand(context, "markdown-title1", "# _title1");
    pushTextInsertCommand(context, "markdown-title2", "## _title2");
    pushTextInsertCommand(context, "markdown-title3", "### _title3");
    pushTextInsertCommand(context, "markdown-title4", "#### _title4");
    pushTextInsertCommand(context, "markdown-title5", "##### _title5");
    pushTextInsertCommand(context, "markdown-title6", "###### _title6");

    pushTextInsertCommand(context, "markdown-list", " - _item1\r\n - _item2\r\n - _item3");
    pushTextInsertCommand(context, "markdown-list-index", " 1. _item1\r\n 1. _item2\r\n 1. _item3");
    pushTextInsertCommand(context, "markdown-list-checkbox", " - [ ] _item1\r\n - [ ] _item2\r\n - [ ] _item3");
    pushTextInsertCommand(context, "markdown-list-checkbox-checked", " - [x] _item1\r\n - [x] _item2\r\n - [x] _item3");

    pushTextInsertCommand(context, "markdown-reference", "> _reference");
    pushTextInsertCommand(context, "markdown-code", "```\r\n_code\r\n```");
    pushTextInsertCommand(context, "markdown-table", "|  _t0 |  _t1  |\r\n|--|--|\r\n| _c00 |  _c01  |\r\n| _c10 | _c11 |");
    pushTextInsertCommand(context, "markdown-link", "[_link](_url)");

    pushTextInsertCommand(context, "markdown-variable", "[_variable]:_value");
    pushTextInsertCommand(context, "markdown-variable-image", "[_variable]:data:image/png;base64,_base64");
    pushTextInsertCommand(context, "markdown-image-variable", "![][_variable]");
    pushTextInsertCommand(context, "markdown-image-base64", "![](data:image/png;base64,_base64)");
    pushTextInsertCommand(context, "markdown-image-url", "![](_url)");
}